﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _80X_CG_Frame.Interfaces
{
    /// <summary>
    /// PLC通信接口
    /// </summary>
    public interface IPLC
    {
        /// <summary>
        /// 连接状态
        /// </summary>
        bool IsConnect { get; }
        /// <summary>
        /// 连接plc
        /// </summary>
        /// <param name="ip">PLC地址</param>
        /// <param name="port">端口</param>
        /// <param name="times"></param>
        /// <returns>连接状态</returns>
        Task<bool> ConnectAsync(string ip, int port, int times = 5);
        /// <summary>
        /// 连接plc, 地址示例127.0.0.1:12450
        /// </summary>
        /// <param name="address">完整地址</param>
        /// <param name="times"></param>
        /// <returns>连接状态</returns>
        Task<bool> ConnectAsync(string address, int times = 5);
        bool Connect(string address, int times = 5);
        /// <summary>
        /// 断开连接
        /// </summary>
        /// <returns></returns>
        bool Disconnect();
        /// <summary>
        /// 是否连接
        /// </summary>
        /// <returns></returns>
        //bool IsConnect();
        /// <summary>
        /// 读双字
        /// </summary>
        /// <param name="dname">寄存器名</param>
        /// <param name="readDwordData">读取的数据</param>
        /// <returns></returns>
        bool ReadDword(string dname, ref int readDwordData);
        bool ReadDword(string dname, ref float readDwordData);
        /// <summary>
        /// 写双字
        /// </summary>
        /// <param name="dname">寄存器名</param>
        /// <param name="writeDwordData">写入的数据</param>
        /// <returns></returns>
        bool WriteDword(string dname, int writeDwordData, double k = 10000);
        bool WriteDword(string dname, float writeDwordData);
        /// <summary>
        /// 读位
        /// </summary>
        /// <param name="mname"></param>
        /// <param name="readMbitdData"></param>
        /// <returns></returns>
        bool ReadMBit(string mname, ref string readMbitdData);
        /// <summary>
        /// 写位
        /// </summary>
        /// <param name="mname"></param>
        /// <param name="writeMbitdData"></param>
        /// <returns></returns>
        bool WriteMBit(string mname, string writeMbitdData);
        bool RefreshMBit();
        string[] ReadMWarning();
        event PropertyChangedEventHandler PropertyChanged;
    }
}
